package cls

import (
	"github.com/gogf/gf/frame/g"
	"strings"
)

type DbColumns struct {
	Prefix string
}

func New(prefix ...string) *DbColumns {
	p := ""
	if len(prefix) > 0 {
		p = prefix[0]
	}
	return &DbColumns{Prefix: p}
}

func (r *DbColumns) Columns(data ...string) string {
	if r.Prefix != "" {
		var s []string
		for _, v := range data {
			s = append(s, r.Prefix+"."+v)
		}
		return strings.Join(s, ",")
	}
	return strings.Join(data, ",")
}
func (r *DbColumns) ExcludeColumns(ColumnsMap g.Map, data ...string) string {
	var s []string
	for _, v := range ColumnsMap {
		for _, v1 := range data {
			if v == v1 {
				delete(ColumnsMap, v1)
			}
		}
	}
	for _, v := range ColumnsMap {
		s = append(s, r.Prefix+"."+v.(string))
	}
	return strings.Join(s, ",")
}
